<?php

require_once 'Zend/Form.php';

class Base_Form extends Zend_Form
{
    public final function __construct($options = null)
    {
		if (Zend_Registry::isRegistered('Zend_Translate')) {
			Zend_Registry::get('Zend_Translate')->addTranslation(
				array(
					'adapter'	=> 'gettext',
					'content'	=> MODULES_PATH .'/../private/language/validate/zh_CN.mo',
					'locale'	=> 'zh_CN',
				)
			);
		}
		
        // Set the method for the display form to POST
        $this->setMethod('post');
		
		$this->addElements(array(
			//
            new Zend_Form_Element_Hash('csrf', array(
				'ignore'   => true,
				'Decorators' =>array(
					'ViewHelper'
				),
            )),
			// Add an submit element
            new Zend_Form_Element_Submit('submit', array(
                'label'      => 'Submit',
				'ignore'   => true,
				'Decorators' =>array(
					'ViewHelper'
				)
            )),
			// Add an reset element
            new Zend_Form_Element_Reset('reset', array(
                'label'      => 'Reset',
				'ignore'     => true,
				'Decorators' => array(
					'ViewHelper'
				),
            )),
			// Add an button element
            new Zend_Form_Element_Button('delete', array(
                'label'      => 'Delete',
				'ignore'     => true,
				'style'      => 'display:none',
				'onClick'    => "location.href='".
                Zend_Controller_Front::getInstance()
                    ->getRouter()->assemble(array('action'=> 'delete')) ."'",
				'decorators' => array(
					'ViewHelper'
				),
            )),
			// Add an button element
            new Zend_Form_Element_Button('back', array(
                'label'      => 'Back',
				'ignore'     => true,
				'onclick'    => "javascript:history.go(-1);",
				'decorators' => array(
					'ViewHelper'
				),
            ))
        ));
        
        $this->addDisplayGroup(
            array('submit', 'reset', 'delete', 'back'), 'button',
			array(
                'order'=> 9,
				'decorators'=> array('FormElements', array('HtmlTag', array('tag' => 'p')))
			)
		);
		
        parent::__construct($options);
    }
}